/*************************************************************************
> File Name: 04_test.cpp
> Author: hzy
> Created Time: 2023-08-14 16:17:20
> Description:  同名成员变量的处理方法
************************************************************************/
#include <iostream>

using namespace std;

class Base
{
public:
    int val;

public:
    Base() : val(0) {}
    void Show()
    {
        cout << val << endl;
    }
};

class Son1 : public Base
{
public:
    int val;

public:
    Son1() : val(10) {}
    void Show()
    {
        cout << "Base:val = " << Base::val << endl;
        cout << "Son1:val = " << val << endl;
    }
    //返回基类重名成员
    int &getBaseVal()
    {
        return Base::val;
    }
};

void test01()
{
    Son1 son1;
    //派生类和基类成员属性重名，子类访问成员默认是子类成员
    cout << "Son1:val = " << son1.val << endl;
    son1.Show();
}

void test02()
{
    Son1 son2;
    son2.getBaseVal() = 99;
    cout << "Base:val = " << son2.getBaseVal() << endl;
}

int main()
{
    test01();
    test02();

    return 0;
}